home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / install.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1998-03-05  |  35KB  |  995 lines

  1. #!/bin/sh
  2. # install.sh
  3. # Prentice Hall CyberClassroom Solaris installation script.
  4. # Deitel C++ How To Program 2e
  5.  
  6. SCRIPT_NAME="$0"
  7.  
  8. # FUNCTION:     cleanup()
  9. # DESCRIPTION:  To uninstall any aborted attempted install, cleanup the "footprints" of any thing the
  10. #               install did to the user's system, and return with the specified error code.
  11. # ARGUMENTS:    $1 - The error code to exit this script with.
  12. # GLOBALS:      Assumes $UNINSTALL_LINE1 $UNINSTALL_LINE2 $UNINSTALL_LINE3 $UNINSTALL_LINE4 are set if need be.
  13. # RETURN VALUE: NONE
  14. cleanup()
  15. {
  16.   echo
  17.   echo "$SCRIPT_NAME: Installation Aborted, cleaning up..."
  18.   echo
  19.   $UNINSTALL_LINE1
  20.   $UNINSTALL_LINE2
  21.   $UNINSTALL_LINE3
  22.   $UNINSTALL_LINE4
  23.   exit $1
  24. }
  25.  
  26.  
  27. # FUNCTION:     two_value_question()
  28. # DESCRIPTION   As a question of the user for input that has 2 allowable answers.
  29. #               The first argument is the first allowable answer the user can type in and
  30. #               also the default answer if the user just hits the enter key. The second argument
  31. #               is the other allowable answer.  The comparison is case INDEPENDENT, in other
  32. #               words the answer "YeS" is the same as "yes".  Also the first letter of the answer
  33. #               is all that is required, however if the user chooses to type the full allowable answer
  34. #               then ONLY the first character is checked, in other words "Yasdfa" will be interpreted
  35. #               as a valid "YES".
  36. #               
  37. # ARGUMENTS:    $1 - first allowable value and also the prompt default
  38. #               $2 - Second allowable value
  39. # GLOBALS:      Assumes $L1 $L2 $L3 $L4 $L5 $L6 $L7 are set if need be.
  40. # RETURN VALUE: $PROMPT_ANSWER set a the first character of the selected prompt.
  41. two_value_question()
  42. {
  43.   FIRST_CHAR_OF_ARG1=`echo $1 | tr "[:lower:]" "[:upper:]" | awk '{print substr($1,1,1)}'` 
  44.   FIRST_CHAR_OF_ARG2=`echo $2 | tr "[:lower:]" "[:upper:]" | awk '{print substr($1,1,1)}'` 
  45.   QUIT_WHILE=0
  46.   while [ $QUIT_WHILE -eq 0 ]
  47.   do
  48.     echo
  49.     if [ "$L1" != "" ]; then
  50.       echo $L1
  51.     fi
  52.     if [ "$L2" != "" ]; then
  53.       echo $L2
  54.     fi
  55.     if [ "$L3" != "" ]; then
  56.       echo $L3
  57.     fi
  58.     if [ "$L4" != "" ]; then
  59.       echo $L4
  60.     fi
  61.     if [ "$L5" != "" ]; then
  62.       echo $L5
  63.     fi
  64.     if [ "$L6" != "" ]; then
  65.       echo $L6
  66.     fi
  67.     if [ "$L7" != "" ]; then
  68.       echo $L7
  69.     fi
  70.     read A_OR_B
  71.     if [ "$A_OR_B" = "" ]; then
  72.       A_OR_B=$1
  73.     fi
  74.     PROMPT_ANSWER=`echo $A_OR_B | tr "[:lower:]" "[:upper:]" | awk '{print substr($1,1,1)}'`
  75.     if [ "$PROMPT_ANSWER" != "$FIRST_CHAR_OF_ARG1" -a "$PROMPT_ANSWER" != "$FIRST_CHAR_OF_ARG2" ]; then
  76.       echo
  77.       echo "Please answer with \"$1\"" or \"$2\"".  Try again."
  78.     else
  79.       QUIT_WHILE=1
  80.     fi
  81.   done
  82.   return 0
  83. }
  84.  
  85.  
  86. trap 'echo;echo "Ctrl-C detected";echo;cleanup 1' 2
  87.  
  88. CYBERCLASSROOM_JRE_VERSION="1.1.5"
  89. CYBERCLASSROOM_JRE_DIRECTORY="jre1.1.5"
  90. CYBERCLASSROOM_VIEWER_VERSION="1.2.0"
  91. #SOLARIS_JRE_RUNTIME=jre115-solaris2-sparc.exe
  92. SOLARIS_JRE_RUNTIME=jre115s.exe
  93. CDROM_DIR=`/usr/bin/pwd`
  94. CYBERCLASSROOM_BOOK_DIR=cpphtp2
  95. CYBERCLASSROOM_BOOK_FILE=cpphtp2.jar
  96. CYBERCLASSROOM_INITIALIZATION_FILE=webdb.ini
  97. CYBERCLASSROOM_HTML_FILE=cpphtp2.htm
  98. CYBERCLASSROOM_VIEWER_DIR=viewer
  99. CYBERCLASSROOM_BOOK_SCRIPT=cpphtp2.sh
  100. CYBERCLASSROOM_BOOK_UNINSTALL_SCRIPT=uninstall.sh
  101. # This book requires at least 350MB of disk space for Full Installation.
  102. CYBERCLASSROOM_BOOK_REQUIRED_SPACE_IN_MB_FOR_FULL=350
  103. CYBERCLASSROOM_BOOK_REQUIRED_SPACE_IN_MB_FOR_COMPACT=35
  104. CYBERCLASSROOM_BOOK_REQUIRED_SPACE_IN_K_FOR_FULL=358400
  105. CYBERCLASSROOM_BOOK_REQUIRED_SPACE_IN_K_FOR_COMPACT=35840
  106.  
  107. UNINSTALL_LINE1=""
  108. UNINSTALL_LINE2=""
  109. UNINSTALL_LINE3=""
  110. UNINSTALL_LINE4=""
  111.  
  112. echo
  113. echo "********************************************************************"
  114. echo "** Welcome to the Prentice Hall CyberClassroom Installation Script *"
  115. echo "**                                                                 *"
  116. echo "** Please follow the prompts where requested.  Options for each    *"
  117. echo "** prompt are enclosed inside circular parenthesis () characters.  *"
  118. echo "** Only the first character for each prompt is necessary, such as  *"
  119. echo "** \"y\" for \"yes\" and \"n\" for \"no\". Default values for each         *"
  120. echo "** prompt are enclosed inside [] characters.                       *"
  121. echo "********************************************************************"
  122.  
  123. # No arguments required for this script
  124. if [ $# -ne 0 ]; then
  125.   echo
  126.   echo "Note: no arguments are required for this installation script."
  127.   echo "The arguments will be ignored."
  128.   echo
  129. fi
  130.  
  131. # Warning message if the current user is not "root"
  132. if [ "$USER" != "root" ]; then
  133.   L5=""; L6=""; L7=""
  134.   L1="WARNING: This installation script creates files and directories "
  135.   L2="on local mount points.  Unless you have proper file permissions "
  136.   L3="the installation may not proceed properly."
  137.   L4="Continue installation as user \"$USER\" ? (yes|no) [no]: \c"
  138.   two_value_question no yes 
  139.   if [ "$PROMPT_ANSWER" != "Y" ]; then
  140.     cleanup 5
  141.   fi
  142.   echo
  143. fi
  144.  
  145.  
  146. INSTALL_JRE=1
  147. JRE_LOCATION=/opt
  148.  
  149.  
  150. L2=""; L3=""; L4=""; L5=""; L6=""; L7=""
  151. L1="Do you have the SunSoft JRE installed ? (yes|no) [no]: \c"
  152. two_value_question no yes
  153. if [ "$PROMPT_ANSWER" = "Y" ]; then
  154.   while [ 1 ]
  155.   do
  156.     JRE_LOCATION=/opt
  157.     INSTALL_JRE=0
  158.  
  159.     # Ask for the "jre" in the current path
  160.     echo
  161.     echo "Where is the SunSoft JRE installed ? (ex: \"/opt/apps/jre${CYBERCLASSROOM_JRE_VERSION}\"): \c"
  162.     read RESPONSE
  163.     if [ "$RESPONSE" = "" ]; then
  164.       echo
  165.       echo "You must type a location, such as \"/opt/apps/jre${CYBERCLASSROOM_JRE_VERSION}\".  Try again."
  166.       echo
  167.       continue
  168.     fi
  169.  
  170.     JRE_LOCATION=$RESPONSE
  171.  
  172.     # Check to see if the user is right
  173.     if [ ! -d $JRE_LOCATION ]; then
  174.         echo
  175.         echo "The directory \"$JRE_LOCATION\" does not exist on your system."
  176.         echo "Please try another path."
  177.         echo
  178.         continue
  179.     fi
  180.  
  181.     # OK Now we have the location
  182.     JRE_EXECUTABLE=$JRE_LOCATION/bin/jre
  183.  
  184.     # Check for the JRE and run it, make sure its the version
  185.     # CyberClassroom needs or a version
  186.     # that is later.
  187.     if [ ! -f $JRE_EXECUTABLE ]; then
  188.       TMP_JRE_LOCATION=$JRE_LOCATION/jre${CYBERCLASSROOM_JRE_VERSION}
  189.       TMP_JRE_EXECUTABLE=$TMP_JRE_LOCATION/bin/jre
  190.       if [ ! -f $TMP_JRE_EXECUTABLE ]; then
  191.         L5=""; L6=""; L7=""
  192.         L1="The executable \"$TMP_JRE_EXECUTABLE\" does not exist "
  193.         L2="Maybe there is a damaged installation of a previous JRE."
  194.         L3="Do you wish to reinstall the JRE in the directory"
  195.         L4="\"$JRE_LOCATION\" ? (yes/no) [yes]: \c"
  196.         two_value_question yes no
  197.         if [ "$PROMPT_ANSWER" = "Y" ]; then
  198.           INSTALL_JRE=1
  199.           break
  200.         else
  201.           L2=""; L3=""; L4=""; L5=""; L6=""; L7=""
  202.           L1="Choose another location? (yes/no) [yes]: \c"
  203.           two_value_question yes no
  204.           if [ "$PROMPT_ANSWER" = "Y" ]; then
  205.             continue
  206.           else
  207.             echo
  208.             echo "$0: ERROR: A possibly damaged installation of the JRE was detected"
  209.             echo "in the directory \"$JRE_LOCATION\"."
  210.             echo "Please correct this problem and run this installation again."
  211.             cleanup 15
  212.           fi
  213.         fi
  214.       else
  215.         JRE_LOCATION=$TMP_JRE_LOCATION
  216.         JRE_EXECUTABLE=$TMP_JRE_EXECUTABLE
  217.       fi
  218.     fi
  219.  
  220.     CURRENT_JRE=`$JRE_EXECUTABLE -help 2>&1 | grep -i Version | awk '{print $NF}'`
  221.     if [ `echo $CURRENT_JRE | awk -F. '{print $1$2$3$4}'` -ne `echo $CYBERCLASSROOM_JRE_VERSION | awk -F. '{print $1$2$3$4}'` ]; then
  222.       L7=""
  223.       L1="The JRE executable [$CURRENT_JRE] on your system"
  224.       L2="is not the version used by the CyberClassroom JRE "
  225.       L3="[jre version \"$CYBERCLASSROOM_JRE_VERSION\"]."
  226.       L4="If you are using a version older than this,"
  227.       L5="it is recommended you install the CyberClassroom JRE version as well."
  228.       L6="Continue and use existing JRE  ? (yes/no) [no]: \c"
  229.       two_value_question no yes
  230.       if [ "$PROMPT_ANSWER" = "Y" ]; then
  231.         INSTALL_JRE=0
  232.       else
  233.         INSTALL_JRE=1
  234.       fi
  235.       break
  236.     else
  237.       break
  238.     fi
  239.  
  240.   done
  241.  
  242. fi
  243.  
  244. # If the JRE needs inst